package com.hspedu.optional;

import org.junit.jupiter.api.Test;

import java.util.Optional;

/**
 * @author 谷其昊
 * @version 1.0
 * @date 2022/3/31
 * @time 15:16
 */
public class OptionalTest {


    @Test
    public void test1(){
        Optional<Boy> boy = Optional.of(new Boy(null));
        String name = null;
        System.out.println("name = " + name);
        System.out.println("name.length() = " + name.length());
    }

    @Test
    public void test2(){
        Boy boy = new Boy();
        Optional<String> name = Optional.ofNullable(boy.getName());
        String alternative = name.orElse(null);
        System.out.println(alternative.length());
    }

}
